package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.tradeapplicationcredit.LindiTradeApplicationCreditQueryVO;
import com.minimalist.common.entity.lindi.vo.tradeapplicationcredit.LindiTradeApplicationCreditVO;
import com.minimalist.common.feign.client.lindi.LindiTradeApplicationCreditFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;

import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 林地交易申请征信 Feign 客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author minimalist
 */
@Component
public class LindiTradeApplicationCreditFeignClientFallbackFactory extends BaseFallbackFactory<LindiTradeApplicationCreditFeignClient>{
    private static final Logger log = LoggerFactory.getLogger(LindiTradeApplicationCreditFeignClientFallbackFactory.class);


    @Override
    public LindiTradeApplicationCreditFeignClient create(Throwable cause){
        return new LindiTradeApplicationCreditFeignClient(){
            @Override
            public R<?> addTradeApplicationCredit(LindiTradeApplicationCreditVO tradeApplicationCreditVO){
                logServiceUnavailable("添加交易申请征信", tradeApplicationCreditVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "添加交易申请征信失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteTradeApplicationCreditByTradeApplicationCreditId(Long tradeApplicationCreditId){
                logServiceUnavailable("删除交易申请征信", tradeApplicationCreditId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "删除交易申请征信失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updateTradeApplicationCreditByTradeApplicationCreditId(LindiTradeApplicationCreditVO tradeApplicationCreditVO){
                logServiceUnavailable("修改交易申请征信", tradeApplicationCreditVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "修改交易申请征信失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiTradeApplicationCreditVO>> getPageTradeApplicationCreditList(LindiTradeApplicationCreditQueryVO queryVO){
                logServiceUnavailable("分页查询交易申请征信列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "分页查询交易申请征信列表失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiTradeApplicationCreditVO> getTradeApplicationCreditByTradeApplicationCreditId(Long tradeApplicationCreditId){
                logServiceUnavailable("获取交易申请征信详情", tradeApplicationCreditId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "获取交易申请征信详情失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<List<LindiTradeApplicationCreditVO>> getTradeApplicationCreditListByTradeApplicationId(Long tradeApplicationId){
                logServiceUnavailable("根据交易申请ID查询付款凭证列表", tradeApplicationId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "根据交易申请ID查询付款凭证列表失败，服务不可用: " + cause.getMessage());
            }
        };
    }
}
